package com.jh.user.pojo.freeQuick;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * 商家提现绑定的结算卡
 */
@Entity
@Table(name = "t_merchant_bank_card")
public class MerchantBankCard implements Serializable {

    private static final long serialVersionUID = 1L;

    public static MerchantBankCard newBankCard() {
        MerchantBankCard bankCard = new MerchantBankCard();
        bankCard.setCreateTime(new Date());
        bankCard.setState("0");
        bankCard.setCardType("1");
        bankCard.setIdDef("0");
        return bankCard;
    }

    public MerchantBankCard updateBankCard(String merchantId, String merchantName, BankCardDTO bankCardDTO) {
        setMerchantId(merchantId);
        setMerchantName(merchantName);
        setBankAccountName(bankCardDTO.getBankAccountName());
        setCardNo(bankCardDTO.getCardNo());
        setBankName(bankCardDTO.getBankName());
        setBankCode(bankCardDTO.getBankAbbr());
        setIdcard(bankCardDTO.getIdCard());
        setPhone(bankCardDTO.getPhone());
        setPriOrPub(Objects.equals(bankCardDTO.getBankAccountType(), "PUBLIC") ? "1" : "0");
        setBankSubName(bankCardDTO.getBankSubName());
        setLineNo(bankCardDTO.getBankChannelNo());
        setProvince(bankCardDTO.getBankCardProvince());
        setCity(bankCardDTO.getBankCardCity());
        setCardType(bankCardDTO.getBankCardType());
        if (Objects.equals(bankCardDTO.getBankCardType(), "2")) {
            setCvn2(bankCardDTO.getCvn2());
        }
        setExpired(bankCardDTO.getPeriod());
        setIdDef(bankCardDTO.getDefaulted());
        setUpdateTime(new Date());
        return this;
    }

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * 商户id
     */
    @Column(name = "shop_id")
    private String merchantId;

    /**
     * 商户名
     */
    @Column(name = "merchant_name")
    private String merchantName;

    /**
     * 银行名称
     */
    @Column(name = "bank_name")
    private String bankName;

    /**
     * 银行编码
     */
    @Column(name = "bank_code")
    private String bankCode;

    /**
     * 品牌编码
     */
    @Column(name = "branch_code")
    private String branchCode;

    /**
     * 银行卡品牌
     */
    @Column(name = "bank_brand")
    private String bankBrand;

    /**
     * 卡的号码
     */
    @Column(name = "card_no")
    private String cardNo;

    /**
     * 银行卡开户名
     */
    @Column(name = "bank_account_name")
    private String bankAccountName;

    /**
     * 银行卡开户行
     */
    @Column(name = "bank_sub_name")
    private String bankSubName;

    /**
     * cvn2(银行卡数字检验码)
     */
    @Column(name = "cvn2")
    private String cvn2;

    /**
     * 卡有效期
     */
    @Column(name = "expired")
    private String expired;

    /**
     * 联行号
     */
    @Column(name = "line_no")
    private String lineNo;

    /**
     * 开户省
     */
    @Column(name = "province")
    private String province;

    /**
     * 开户市
     */
    @Column(name = "city")
    private String city;

    /**
     * 预留手机号码
     */
    @Column(name = "phone")
    private String phone;

    /**
     * 身份证号
     */
    @Column(name = "id_card")
    private String idcard;

    /**
     * 卡的类型， 1借记卡，2信用卡
     */
    @Column(name = "card_type")
    private String cardType;

    /**
     * 0对私还1对公帐户
     */
    @Column(name = "pri_or_pub")
    private String priOrPub = "0";

    /**
     * 区别
     **/
    @Column(name = "nature")
    private String nature;

    /**
     * 使用状态0正常1禁用
     */
    @Column(name = "state")
    private String state = "0";

    /**
     * 是否默认结算卡(1默认 0非默认)
     */
    @Column(name = "is_def")
    private String idDef;

    /**
     * logo
     */
    @Column(name = "logo")
    private String logo;

    @Column(name = "create_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Column(name = "update_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getMerchantName() {
        return merchantName;
    }

    public void setMerchantName(String merchantName) {
        this.merchantName = merchantName;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getBankCode() {
        return bankCode;
    }

    public void setBankCode(String bankCode) {
        this.bankCode = bankCode;
    }

    public String getBranchCode() {
        return branchCode;
    }

    public void setBranchCode(String branchCode) {
        this.branchCode = branchCode;
    }

    public String getBankBrand() {
        return bankBrand;
    }

    public void setBankBrand(String bankBrand) {
        this.bankBrand = bankBrand;
    }

    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    public String getBankAccountName() {
        return bankAccountName;
    }

    public void setBankAccountName(String bankAccountName) {
        this.bankAccountName = bankAccountName;
    }

    public String getBankSubName() {
        return bankSubName;
    }

    public void setBankSubName(String bankSubName) {
        this.bankSubName = bankSubName;
    }

    public String getCvn2() {
        return cvn2;
    }

    public void setCvn2(String cvn2) {
        this.cvn2 = cvn2;
    }

    public String getExpired() {
        return expired;
    }

    public void setExpired(String expired) {
        this.expired = expired;
    }

    public String getLineNo() {
        return lineNo;
    }

    public void setLineNo(String lineNo) {
        this.lineNo = lineNo;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public String getCardType() {
        return cardType;
    }

    public void setCardType(String cardType) {
        this.cardType = cardType;
    }

    public String getPriOrPub() {
        return priOrPub;
    }

    public void setPriOrPub(String priOrPub) {
        this.priOrPub = priOrPub;
    }

    public String getNature() {
        return nature;
    }

    public void setNature(String nature) {
        this.nature = nature;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getIdDef() {
        return idDef;
    }

    public void setIdDef(String idDef) {
        this.idDef = idDef;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * 是否是默认卡
     */
    public boolean isDefCard() {
        return Objects.equals(getIdDef(), "1");
    }
}
